package com.Questions.DFS;


import java.util.*;

/**
 * 二叉树前序遍历
 */
public class leetcode144 {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        return traveTree(root,res);

    }
    public List<Integer> traveTree(TreeNode root,List<Integer> res){
        if(root==null){
            return res;
        }
        res.add(root.val);
        traveTree(root.left,res);
        traveTree(root.right,res);
        return res;
    }

}
